package middleware.mq;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

/**
 *
 * 单向发送消息
 *
 * 场景：
 * 不特别关心发送结果的场景，例如日志发送
 *
 * Author: shen qi han
 * Date: 2022/4/3 下午10:49
 */
public class OneWayProducerMain {

    public static void main(String[] args) throws Exception{
        // init the producer
        DefaultMQProducer producer = new DefaultMQProducer("taskGroup");
        // set the nameServer addr
        producer.setNamesrvAddr("localhost:9876");
        // start instance
        producer.start();

        // item msg
        Message msg = new Message("TopicTask",
                "TagML",
                "jsonInfo".getBytes(RemotingHelper.DEFAULT_CHARSET));
        // send to msg, not need return info
        producer.sendOneway(msg);

        // shut down
        producer.shutdown();
    }

}
